package com.twu.biblioteca;

public class Validator {

    public static boolean validateMovieRating(String rating) throws InvalidMovieRatingException {
        if (rating.equals("N/A")) return true;
        else {
            try {
                double numberRating = Double.parseDouble(rating);
                if (numberRating < 1 || numberRating > 10)
                    throw new InvalidMovieRatingException();
            } catch (NumberFormatException e) {
                throw new InvalidMovieRatingException();
            }
        }
        return true;
    }

    public static String validateLibraryFormat(int libraryCardNumber) {
        return String.valueOf(libraryCardNumber).substring(0, 3) + "-" + String.valueOf(libraryCardNumber).substring(3, 7);
    }

    public boolean validateChoiceAndPrintWarning(int choice, int optionListSize) throws InputNotValidException {
        if (!(choice <= optionListSize && choice > 0)) {
            throw new InputNotValidException();
        }
        return true;
    }
}


